package jsen.tool.ddd.demo.domain.parking.spec.parking;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;
import jsen.tool.ddd.adapter.infrastructure.specification.base.SpecContext;
import jsen.tool.ddd.demo.domain.parking.ParkingLotStatus;

/**
 * @author jsen
 * @date 2021/10/6
 */
public class ParkingLotStatusSpec implements ISpecification<ParkingLotStatus> {
    @Override
    public boolean isSatisfiedBy(SpecContext<ParkingLotStatus> t) {
        ParkingLotStatus location = t.getData();
        if (location.getBusyLocationCnt() < 0 || location.getFreeLocationCnt() < 0 || location.getCarCnt() < 0) {
            t.addError("ParkingLotStatus", "停车场统计状态错误");
            return false;
        }
        return true;
    }
}
